package com.holly.unit.bpmn.modular.activiti.config;


import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.AbstractProcessEngineAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * 类描述: activiti工作流的数据源配置
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/1/25 9:37
 */
@Configuration
public class ActivitiDataSourceConfig extends AbstractProcessEngineAutoConfiguration {

    @Resource
    private DataSource dataSource;

//    @Resource
//    private DruidProperties druidProperties;

//    @ConditionalOnMissingBean(DataSource.class)
//    public DataSource activitiDataSource() {
//        DruidDataSource druiddataSource = new DruidDataSource();
//        druiddataSource.setUrl(druidProperties.getUrl());
//        druiddataSource.setDriverClassName(druidProperties.getDriverClassName());
//        druiddataSource.setPassword(druidProperties.getPassword());
//        druiddataSource.setUsername(druidProperties.getUsername());
//        return druiddataSource;
//    }

    @ConditionalOnMissingBean(PlatformTransactionManager.class)
    public PlatformTransactionManager transactionManager() {
        return new DataSourceTransactionManager(dataSource);
    }

    @Bean
    public SpringProcessEngineConfiguration springProcessEngineConfiguration() {
        SpringProcessEngineConfiguration configuration = new SpringProcessEngineConfiguration();
        configuration.setDataSource(dataSource);
        configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        configuration.setJobExecutorActivate(false);
        configuration.setTransactionManager(transactionManager());
        configuration.setActivityFontName("宋体");
        configuration.setLabelFontName("宋体");
        configuration.setAnnotationFontName("宋体");
        return configuration;
    }

}
